home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / jpsrc2.zip / JDMCU.C < prev    next >
C/C++ Source or Header  |  1991-10-03  |  4KB  |  147 lines

  1. /*
  2.  * jdmcu.c
  3.  *
  4.  * Copyright (C) 1991, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains MCU disassembly routines and quantization descaling.
  9.  * These routines are invoked via the disassemble_MCU and
  10.  * disassemble_init/term methods.
  11.  */
  12.  
  13. #include "jinclude.h"
  14.  
  15.  
  16. /*
  17.  * Quantization descaling and zigzag reordering
  18.  */
  19.  
  20.  
  21. /* ZAG[i] is the natural-order position of the i'th element of zigzag order. */
  22.  
  23. static const short ZAG[DCTSIZE2] = {
  24.   0,  1,  8, 16,  9,  2,  3, 10,
  25.  17, 24, 32, 25, 18, 11,  4,  5,
  26.  12, 19, 26, 33, 40, 48, 41, 34,
  27.  27, 20, 13,  6,  7, 14, 21, 28,
  28.  35, 42, 49, 56, 57, 50, 43, 36,
  29.  29, 22, 15, 23, 30, 37, 44, 51,
  30.  58, 59, 52, 45, 38, 31, 39, 46,
  31.  53, 60, 61, 54, 47, 55, 62, 63
  32. };
  33.  
  34.  
  35. LOCAL void
  36. qdescale_zig (JBLOCK input, JBLOCKROW outputptr, QUANT_TBL_PTR quanttbl)
  37. {
  38.   short i;
  39.  
  40.   for (i = 0; i < DCTSIZE2; i++) {
  41.     (*outputptr)[ZAG[i]] = (*input++) * (*quanttbl++);
  42.   }
  43. }
  44.  
  45.  
  46.  
  47. /*
  48.  * Fetch one MCU row from entropy_decode, build coefficient array.
  49.  * This version is used for noninterleaved (single-component) scans.
  50.  */
  51.  
  52. METHODDEF void
  53. disassemble_noninterleaved_MCU (decompress_info_ptr cinfo,
  54.                 JBLOCKIMAGE image_data)
  55. {
  56.   JBLOCK MCU_data[1];
  57.   long mcuindex;
  58.   jpeg_component_info * compptr;
  59.   QUANT_TBL_PTR quant_ptr;
  60.  
  61.   /* this is pretty easy since there is one component and one block per MCU */
  62.   compptr = cinfo->cur_comp_info[0];
  63.   quant_ptr = cinfo->quant_tbl_ptrs[compptr->quant_tbl_no];
  64.   for (mcuindex = 0; mcuindex < cinfo->MCUs_per_row; mcuindex++) {
  65.     /* Fetch the coefficient data */
  66.     (*cinfo->methods->entropy_decode) (cinfo, MCU_data);
  67.     /* Descale, reorder, and distribute it into the image array */
  68.     qdescale_zig(MCU_data[0], image_data[0][0] + mcuindex, quant_ptr);
  69.   }
  70. }
  71.  
  72.  
  73. /*
  74.  * Fetch one MCU row from entropy_decode, build coefficient array.
  75.  * This version is used for interleaved (multi-component) scans.
  76.  */
  77.  
  78. METHODDEF void
  79. disassemble_interleaved_MCU (decompress_info_ptr cinfo,
  80.                  JBLOCKIMAGE image_data)
  81. {
  82.   JBLOCK MCU_data[MAX_BLOCKS_IN_MCU];
  83.   long mcuindex;
  84.   short blkn, ci, xpos, ypos;
  85.   jpeg_component_info * compptr;
  86.   QUANT_TBL_PTR quant_ptr;
  87.   JBLOCKROW image_ptr;
  88.  
  89.   for (mcuindex = 0; mcuindex < cinfo->MCUs_per_row; mcuindex++) {
  90.     /* Fetch the coefficient data */
  91.     (*cinfo->methods->entropy_decode) (cinfo, MCU_data);
  92.     /* Descale, reorder, and distribute it into the image array */
  93.     blkn = 0;
  94.     for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  95.       compptr = cinfo->cur_comp_info[ci];
  96.       quant_ptr = cinfo->quant_tbl_ptrs[compptr->quant_tbl_no];
  97.       for (ypos = 0; ypos < compptr->MCU_height; ypos++) {
  98.     image_ptr = image_data[ci][ypos] + (mcuindex * compptr->MCU_width);
  99.     for (xpos = 0; xpos < compptr->MCU_width; xpos++) {
  100.       qdescale_zig(MCU_data[blkn], image_ptr, quant_ptr);
  101.       image_ptr++;
  102.       blkn++;
  103.     }
  104.       }
  105.     }
  106.   }
  107. }
  108.  
  109.  
  110. /*
  111.  * Initialize for processing a scan.
  112.  */
  113.  
  114. METHODDEF void
  115. disassemble_init (decompress_info_ptr cinfo)
  116. {
  117.   /* no work for now */
  118. }
  119.  
  120.  
  121. /*
  122.  * Clean up after a scan.
  123.  */
  124.  
  125. METHODDEF void
  126. disassemble_term (decompress_info_ptr cinfo)
  127. {
  128.   /* no work for now */
  129. }
  130.  
  131.  
  132.  
  133. /*
  134.  * The method selection routine for MCU disassembly.
  135.  */
  136.  
  137. GLOBAL void
  138. jseldmcu (decompress_info_ptr cinfo)
  139. {
  140.   if (cinfo->comps_in_scan == 1)
  141.     cinfo->methods->disassemble_MCU = disassemble_noninterleaved_MCU;
  142.   else
  143.     cinfo->methods->disassemble_MCU = disassemble_interleaved_MCU;
  144.   cinfo->methods->disassemble_init = disassemble_init;
  145.   cinfo->methods->disassemble_term = disassemble_term;
  146. }
  147.